package cn.tedu.ivos.user.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.user.pojo.dto.UserLoginDTO;
import cn.tedu.ivos.user.pojo.dto.UserSaveParam;
import cn.tedu.ivos.user.pojo.dto.UserSelectParam;
import cn.tedu.ivos.user.pojo.dto.UserUpdateParam;
import cn.tedu.ivos.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "01.用戶模塊")
@Slf4j
@RestController
@RequestMapping("/v1/user/")
public class UserController {
    @Autowired
    private UserService userService;
    @ApiOperation("登錄功能")
    @PostMapping("login")
    public JsonResult login(@Validated UserLoginDTO userLoginDTO){
        return userService.login(userLoginDTO);
    }
    @ApiOperation("新增用戶")
    @PostMapping("save")
    public JsonResult save(@Validated UserSaveParam userSaveParam){
        return userService.save(userSaveParam);
    }
    @ApiOperation("查詢用戶")
    @GetMapping("select")
    public JsonResult select(UserSelectParam userSelectParam){
        return userService.select(userSelectParam);
    }
    @ApiOperation("查詢領導")
    @GetMapping("selectLevel")
    public JsonResult selectLevel(Integer level){
        return userService.selectLevel(level);
    }
    @ApiOperation("修改用戶")
    @PostMapping("update")
    public JsonResult update(UserUpdateParam userSaveParam){
        return userService.update(userSaveParam);
    }
    @ApiOperation("刪除用戶")
    @PostMapping("del")
    public JsonResult del(Long id){
        System.out.println("id = " + id);
        return userService.del(id);
    }
}
